package utils;

import android.database.Cursor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 * Created by Administrator on 2016/4/24.
 */
public class TableDao  {

    public static List<Map<String, Object>> getAllData(int nowStage) {
        List<Map<String,Object>> values = new ArrayList<>();
        String sql = "select id from main_tab";
        Cursor c = Globals.sdb.getReadableDatabase().rawQuery(sql, null);
        c.moveToFirst();
        while (!c.isAfterLast()) {
            Map<String,Object> map = new HashMap<>();
            map.put("stageTxt",c.getInt(0));
            //要选择的关卡比id大，则可以玩，id的初始值为1
            if(nowStage>=c.getInt(0)) {
                map.put("flag",true);
            }else {
                map.put("flag",false);
            }

            values.add(map);
            c.moveToNext();
        }
        c.close();
        return values;
    }

    public static Map<String, Object> getDataById(int id) {
        Map<String, Object> map = new HashMap<>();
        String sql = " select img_title, img_path, img_answer, all_text from main_tab where id=?";
        Cursor c = Globals.sdb.getReadableDatabase().rawQuery(sql, new String[]{id+""});
        c.moveToFirst();
        map.put("imgTitle", c.getString(0));
        map.put("imgPath", c.getString(1));
        map.put("imgAnswer", c.getString(2));
        map.put("allText", c.getString(3));
        c.close();
        return map;
    }
}
